package Demo4;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/container-with-most-water/description/
 * 盛水最多的容器
 * 创建一个变量max 作为返回值
 * 创建两个指针,一个指向0 一个指向数组的末尾
 * 遍历数组,拿到盛水的最大值,返回
 */
class Solution {
    public int maxArea(int[] height) {
        int max = 0;
        int left = 0;
        int right = height.length - 1;
        while(left < right) {
            int v = Math.min(height[left], height[right]) * (right - left);
            max = Math.max(v,max);
            if(height[left] < height[right]) {
                left++;
            }else {
                right--;
            }
        }
        return max;
    }
}